home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / bash_completion.d / dpkg < prev    next >
Encoding:
Text File  |  2010-11-16  |  7.7 KB  |  245 lines

  1. # This function is required by _dpkg() and _dpkg-reconfigure()
  2. have dpkg && {
  3. have grep-status && {
  4. _comp_dpkg_installed_packages()
  5. {
  6.     grep-status -P -e "^$1" -a -FStatus 'install ok installed' -n -s Package
  7. }
  8. } || {
  9. _comp_dpkg_installed_packages()
  10. {
  11.     command grep -A 1 "Package: $1" /var/lib/dpkg/status | \
  12.         command grep -B 1 -Ee "ok installed|half-installed|unpacked| \
  13.             half-configured|config-files" \
  14.             -Ee "^Essential: yes" | \
  15.         command grep "Package: $1" | cut -d\  -f2
  16. }
  17. }
  18.  
  19. # Debian dpkg(8) completion
  20. #
  21. _dpkg()
  22. {
  23.     local cur prev i
  24.  
  25.     COMPREPLY=()
  26.     _get_comp_words_by_ref cur prev
  27.     i=$COMP_CWORD
  28.  
  29.     _expand || return 0
  30.  
  31.     _split_longopt
  32.  
  33.     # find the last option flag
  34.     if [[ $cur != -* ]]; then
  35.         while [[ $prev != -* && $i != 1 ]]; do
  36.             i=$((i-1))
  37.             prev=${COMP_WORDS[i-1]}
  38.         done
  39.     fi
  40.  
  41.     case $prev in
  42.         -c|-i|-A|-I|-f|-e|-x|-X|-W|--install|--unpack|--record-avail| \
  43.         --contents|--info|--fsys-tarfile|--field|--control|--extract| \
  44.         --show)
  45.             _filedir '?(u)deb'
  46.             return 0
  47.             ;;
  48.         -b|--build)
  49.             _filedir -d
  50.             return 0
  51.             ;;
  52.         -s|-p|-l|--status|--print-avail|--list)
  53.             COMPREPLY=( $( apt-cache pkgnames "$cur" 2>/dev/null ) )
  54.             return 0
  55.             ;;
  56.         -S|--search)
  57.             _filedir
  58.             return 0
  59.             ;;
  60.         -r|-L|-P|--remove|--purge|--listfiles)
  61.             COMPREPLY=( $( _comp_dpkg_installed_packages "$cur" ) )
  62.             return 0
  63.             ;;
  64.         *)
  65.             COMPREPLY=( $( compgen -W '-i --install --unpack -A --record-avail \
  66.                 --configure -r --remove -P --purge --get-selections \
  67.                 --set-selections --update-avail --merge-avail \
  68.                 --clear-avail  --command-fd --forget-old-unavail -s \
  69.                 --status -p --print-avail -L --listfiles -l --list \
  70.                 -S --search -C --audit --print-architecture \
  71.                 --print-gnu-build-architecture \
  72.                 --print-installation-architecture \
  73.                 --compare-versions --help --version --force-help \
  74.                 --force-all --force-auto-select --force-downgrade \
  75.                 --force-configure-any --force-hold --force-bad-path \
  76.                 --force-not-root --force-overwrite \
  77.                 --force-overwrite-diverted --force-bad-verify \
  78.                 --force-depends-version --force-depends \
  79.                 --force-confnew --force-confold --force-confdef \
  80.                 --force-confmiss --force-conflicts --force-architecture\
  81.                 --force-overwrite-dir --force-remove-reinstreq \
  82.                 --force-remove-essential -Dh \
  83.                 --debug=help --licence --admindir --root --instdir \
  84.                 -O --selected-only -E --skip-same-version \
  85.                 -G --refuse-downgrade -B --auto-deconfigure \
  86.                 --no-debsig --no-act -D --debug --status-fd \
  87.                 -b --build -I --info -f --field -c --contents \
  88.                 -x --extract -X --vextract --fsys-tarfile -e --control \
  89.                 --ignore-depends --abort-after' -- "$cur" ) )
  90.             ;;
  91.     esac
  92.  
  93.  
  94. }
  95. complete -F _dpkg -o filenames dpkg dpkg-deb
  96. }
  97.  
  98. # Debian GNU dpkg-reconfigure(8) completion
  99. #
  100. have dpkg-reconfigure &&
  101. _dpkg_reconfigure()
  102. {
  103.     local cur prev opt
  104.  
  105.     COMPREPLY=()
  106.     _get_comp_words_by_ref cur prev
  107.  
  108.     case $prev in
  109.         -f|--frontend)
  110.         opt=( $( printf '%s\n' /usr/share/perl5/Debconf/FrontEnd/* ) )
  111.         opt=( ${opt[@]##*/} )
  112.         opt=( ${opt[@]%.pm} )
  113.         COMPREPLY=( $( compgen -W '${opt[@]}' -- "$cur" ) )
  114.         return 0
  115.         ;;
  116.         -p|--priority)
  117.         COMPREPLY=( $( compgen -W 'low medium high critical' -- "$cur" ) )
  118.         return 0
  119.         ;;
  120.     esac
  121.  
  122.     if [[ "$cur" == -* ]]; then
  123.         COMPREPLY=( $(compgen -W '--frontend --priority --all --unseen-only \
  124.                       --help --showold --force --terse' -- "$cur" ) )
  125.     else
  126.         COMPREPLY=( $( _comp_dpkg_installed_packages "$cur" ) )
  127.     fi
  128. } &&
  129. complete -F _dpkg_reconfigure -o default dpkg-reconfigure
  130.  
  131. # Debian dpkg-source completion
  132. #
  133. have dpkg-source &&
  134. _dpkg_source()
  135. {
  136.     local cur prev options work i action packopts unpackopts fields
  137.  
  138.     packopts="-c -l -F -V -T -D -U -W -E -sa -i -I -sk -sr -ss -sA -sK -sP \
  139.               -sU -sR"
  140.     unpackopts="-sp -sn -su"
  141.     options="-x -b $packopts $unpackopts"
  142.     fields="Format Source Version Binary Maintainer Uploader Architecture \
  143.             Standards-Version Build-Depends Files"
  144.  
  145.     COMPREPLY=()
  146.     _get_comp_words_by_ref cur prev
  147.  
  148.     action="options"
  149.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  150.         if [[ ${COMP_WORDS[$i]} == "-x" ]]; then
  151.             action=unpack
  152.         elif [[ ${COMP_WORDS[$i]} == "-b" ]]; then
  153.             action=pack
  154.         elif [[ ${COMP_WORDS[$i]} == "-h" ]]; then
  155.             action=help
  156.         fi
  157.     done
  158.  
  159.     case $action in
  160.         unpack)
  161.             case $prev in
  162.                 -x)
  163.                     _filedir -d
  164.                     _filedir 'dsc'
  165.                     return 0
  166.                     ;;
  167.                 *)
  168.                     COMPREPLY=( $( compgen -W "$unpackopts" -- "$cur" ) )
  169.                     _filedir -d
  170.                     _filedir
  171.                     return 0
  172.                     ;;
  173.             esac
  174.             return 0
  175.             ;;
  176.         pack)
  177.             case $prev in
  178.                 -b)
  179.                     _filedir -d
  180.                     return 0
  181.                     ;;
  182.                 -c|-l|-T|-i|-I)
  183.                     # -c: get controlfile
  184.                     # -l: get per-version info from this file
  185.                     # -T: read variables here, not debian/substvars
  186.                     # -i: <regexp> filter out files to ignore diffs of.
  187.                     # -I: filter out files when building tarballs.
  188.                     # return directory names and file names
  189.                     _filedir -d
  190.                     _filedir
  191.                     return 0
  192.                     ;;
  193.                 -F)
  194.                     # -F: force change log format
  195.                     COMPREPLY=( $( command ls /usr/lib/dpkg/parsechangelog ) )
  196.                     return 0
  197.                     ;;
  198.                 -V|-D)
  199.                     # -V: set a substitution variable
  200.                     # we don't know anything about possible variables or values
  201.                     # so we don't try to suggest any completion.
  202.                     COMPREPLY=()
  203.                     return 0
  204.                     ;;
  205.                 -D)
  206.                     # -D: override or add a .dsc field and value
  207.                     # if $cur doesn't contain a = yet, suggest variable names
  208.                     if [[ "$cur" == *=* ]]; then
  209.                         # $cur contains a "="
  210.                         COMPREPLY=()
  211.                         return 0
  212.                     else
  213.                         COMPREPLY=( $( compgen -W "$fields" -- "$cur" ) )
  214.                         return 0
  215.                     fi
  216.                     ;;
  217.                 -U)
  218.                     # -U: remove a field
  219.                     # Suggest possible fieldnames
  220.                     COMPREPLY=( $( compgen -W "$fields" -- "$cur" ) )
  221.                     return 0
  222.                     ;;
  223.                 *)
  224.                     COMPREPLY=( $( compgen -W "$packopts $unpackopts" -- "$cur" ) )
  225.                     return 0
  226.                     ;;
  227.             esac
  228.             return 0
  229.             ;;
  230.         *)
  231.             COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
  232.             return 0
  233.             ;;
  234.     esac
  235. } &&
  236. complete -F _dpkg_source dpkg-source
  237.  
  238. # Local variables:
  239. # mode: shell-script
  240. # sh-basic-offset: 4
  241. # sh-indent-comment: t
  242. # indent-tabs-mode: nil
  243. # End:
  244. # ex: ts=4 sw=4 et filetype=sh
  245.